import Mock, { Random } from 'mockjs'
import { doCustomTimes } from '@/libs/util'

export const getAgentTableData = req => {
  const total = Random.integer(30, 58)
  const tableData = []
  const { pageSize, current, search = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = search !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, () => {
    tableData.push(
      Mock.mock({
        Agent_Name: '@cparagraph(1)',
        Agent_Type: '@cword(2, 4)',
        Agent_Address: '@cparagraph(1)',
        Agent_Phone: '@phone',
        Agent_Person: '@cname',
        Agent_Remark: '@cparagraph(1, 3)',
        img: "@dataImage('100x125', '追日电气')"
      })
    )
  })
  return {
    total: search === '' ? total : num,
    tableData
  }
}

export const getUserList = req => {
  const total = Random.integer(0, 10)
  const tableData = []
  const { pageSize, current, search = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = search !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, () => {
    tableData.push(
      Mock.mock({
        Agent_Name: '@cparagraph(1)',
        username: '@cname',
        password: '@word(6)',
        username2: '@cname',
        phone: '@phone',
        email: '@email',
        LastLoginIP: '@ip',
        LastLoginTime: "@datetime('yyyy-MM-dd HH:mm:ss')"
      })
    )
  })
  return {
    total: search === '' ? total : num,
    tableData
  }
}

export const getAgentChargeStationData = req => {
  const total = Random.integer(0, 35)
  const tableData = []
  const { pageSize, current, search = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = search !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, () => {
    tableData.push(
      Mock.mock({
        chargeStationName: '@cparagraph(1)',
        chargeStationAddress: '@cparagraph(1)',
        buildTime: "@datetime('yyyy-MM-dd HH:mm:ss')",
        phone: '@phone',
        email: '@email',
        contact: '@cname',
        note: '@cparagraph(0, 1)',
        number: '@integer(0, 10)',
        longitude: '106.259558',
        dimension: '27.504441',
        img: "@dataImage('100x125', '追日电气')",
        serviceCost: '@float(0, 100, 2, 2)',
        parkCost: '@float(0, 30, 2, 2)'
      })
    )
  })
  return {
    total: search === '' ? total : num,
    tableData
  }
}

export const getAgentSelectStationTimeCostData = req => {
  const list = []
  // const { chargeName } = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  const num = Random.integer(0, 12)
  doCustomTimes(num, () => {
    list.push(
      Mock.mock({
        startTime: '@time("HH:mm")',
        endTime: '@time("HH:mm")',
        cost: '@float(0, 3, 2, 2)'
      })
    )
  })
  return list
}

export const getAgentPileData = req => {
  const total = Random.integer(0, 50)
  const tableData = []
  const { pageSize, current, search = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = search !== '' ? Random.integer(0, 5) : num
  let index = 0
  doCustomTimes(num, () => {
    tableData.push(
      Mock.mock({
        pileCoding: '@phone',
        name: function () {
          return ++index + '号桩'
        },
        release: function () {
          return 'v1.3.' + Random.integer(0, 9)
        },
        status: function () {
          const r = Random.integer(0, 1000)
          if (r % 3 === 0) {
            return '待机'
          } else if (r % 3 === 1) {
            return '故障'
          } else {
            return '正常'
          }
        },
        type: function () {
          const r = Random.integer(0, 10)
          if (r % 2 === 0) {
            return '直流'
          } else {
            return '交流'
          }
        },
        gunNumber: '@integer(1, 4)',
        power: '@float(100, 130, 4, 4)'
      })
    )
  })
  return {
    total: search === '' ? total : num,
    tableData
  }
}

export const getCustomInfoData = req => {
  const total = Random.integer(0, 60)
  const tableData = []
  const { pageSize, current, customName = '', customNumber = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = customName !== '' || customNumber !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, () => {
    tableData.push(
      Mock.mock({
        customName: '@name',
        vip: '@integer(0, 10)',
        customNumber: '@integer(0, 10000)',
        contact: '@cname',
        phone: '@phone',
        note: '@cparagraph(0, 1)'
      })
    )
  })
  return {
    total: customName === '' && customNumber === '' ? total : num,
    tableData
  }
}

export const getAppUserManageInfo = req => {
  const total = Random.integer(0, 60)
  const tableData = []
  const { pageSize, current, customName = '', customNumber = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = customName !== '' || customNumber !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, () => {
    tableData.push(
      Mock.mock({
        phoneNumber: '@phone',
        phoneOwnerName: '@name',
        LicensePlateNumber: '@licensePlate',
        firstLoadTime: '@time("yyyy-MM-dd HH:mm")',
        sumConsume: '@float(100, 10000, 0, 2)',
        loveBusType: '@pick(["本田", "大众", "通用", "特斯拉"])',
        pwd: '@string',
        userStatus: '@pick(["0", "1"])'
      })
    )
  })
  return {
    total: customName === '' && customNumber === '' ? total : num,
    tableData
  }
}

export const getAppSuggestFeedbackInfo = req => {
  const total = Random.integer(0, 60)
  const tableData = []
  const { pageSize, current, customName = '', customNumber = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = customName !== '' || customNumber !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, i => {
    tableData.push(
      Mock.mock({
        feedbackTime: '@time("yyyy-MM-dd HH:mm:ss")',
        phoneNumber: '@phone',
        suggestion: '@cparagraph(1)',
        id: i
      })
    )
  })
  return {
    total: customName === '' && customNumber === '' ? total : num,
    tableData
  }
}

export const getLoginUserInfo = req => {
  const total = Random.integer(0, 60)
  const tableData = []
  const { pageSize, current, customName = '', customNumber = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = customName !== '' || customNumber !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, i => {
    tableData.push(
      Mock.mock({
        loginUser: '@name',
        status: '@pick(["0", "1"])',
        name: '@name',
        phone: '@phone',
        email: '@email',
        role: '@pick(["test", "test2"])',
        lastIP: '@ip',
        lastTime: '@time("yyyy-MM-dd HH:mm:ss")',
        pwd: '@string',
        id: i
      })
    )
  })
  return {
    total: customName === '' && customNumber === '' ? total : num,
    tableData
  }
}

export const getUserRoleList = req => {
  const total = Random.integer(0, 60)
  const tableData = []
  const { pageSize, current, customName = '', customNumber = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = customName !== '' || customNumber !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, i => {
    tableData.push(
      Mock.mock({
        roleName: '@name',
        agent: '@name',
        station: '@name',
        desc: '@cparagraph',
        id: i
      })
    )
  })
  return {
    total: customName === '' && customNumber === '' ? total : num,
    tableData
  }
}

export const getUserLoginLogInfo = req => {
  const total = Random.integer(0, 60)
  const tableData = []
  const { pageSize, current, customName = '', customNumber = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = customName !== '' || customNumber !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, i => {
    tableData.push(
      Mock.mock({
        agent: '@name',
        station: '@name',
        username: '@name',
        lastIP: '@ip',
        lastTime: '@time("yyyy-MM-dd HH:mm:ss")',
        id: i
      })
    )
  })
  return {
    total: customName === '' && customNumber === '' ? total : num,
    tableData
  }
}

export const getSystemMsgInfo = req => {
  const total = Random.integer(0, 60)
  const tableData = []
  const { pageSize, current, customName = '', customNumber = '' } =
    typeof req.body === 'string' ? JSON.parse(req.body) : req.body
  let num =
    current * pageSize > total ? total - pageSize * (current - 1) : pageSize
  num = customName !== '' || customNumber !== '' ? Random.integer(0, 5) : num
  doCustomTimes(num, i => {
    tableData.push(
      Mock.mock({
        title: '@name',
        content: '@cparagraph',
        publishTime: '@time("yyyy-MM-dd HH:mm:ss")',
        publisher: '@cname',
        isValid: '@pick(["0", "1"])',
        type: '@pick(["system", "addStation"])',
        id: i
      })
    )
  })
  return {
    total: customName === '' && customNumber === '' ? total : num,
    tableData
  }
}

export const setFormData = req => {
  return Promise.resolve()
}
